﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace EierFarmDAL
{
    public enum HenBreed
    {
        e_BW,
        e_Bayern,
        e_Other
    }
    public class Huhn : INotifyPropertyChanged
    {
        #region Fields

        private int _weight;
        private string _name;
        private ObservableCollection<Egg> _eggList;
        private HenBreed _breed;

        #endregion Fields

        #region Cstr / Dstr

        public Huhn()
        {
            Weight = (new Random().Next(500, 5000));
            Eggs = new ObservableCollection<Egg>();
            Name = "Huhn";
        }

        public Huhn(string name, HenBreed breed)
        {
            Weight = (new Random().Next(500, 5000));
            Eggs = new ObservableCollection<Egg>();
            Name = name;
            _breed = breed;
        }

        #endregion Cstr / Dstr

        #region Properties

        public int Weight
        {
            get { return _weight; }
            set
            {
                _weight = value;
                OnPropertyChanged("Weight");
            }
        }

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                OnPropertyChanged("Name");
            }
        }

        public ObservableCollection<Egg> Eggs
        {
            get { return _eggList; }
            set
            {
                _eggList = value;
                //OnPropertyChanged("Eggs");
            }
        }

        #endregion Properties

        public void Feed()
        {
            if (Weight < 3000)
            {
                Weight += 100;
            }
        }

        public void EggLaying()
        {
            var clr = EggColor.e_Bright;
            if(_breed == HenBreed.e_Bayern)
                clr = EggColor.e_Dark;
            if (Weight > 1500)
            {
                Eggs.Add(new Egg(100, clr));
                Weight -= 100;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}